package cn.ihuizi.service.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import com.sun.org.apache.bcel.internal.generic.NEW;

import cn.ihuizi.dao.AdminDao;
import cn.ihuizi.dao.impl.AdminDaoImpl;
import cn.ihuizi.entity.Admin;
import cn.ihuizi.entity.Role;
import cn.ihuizi.service.AdminService;

public class AdminServiceImpl implements AdminService {
	AdminDao adminDao = new AdminDaoImpl();
	@Override
	public boolean updateAdminSel(Admin admin) {
		// TODO Auto-generated method stub
		
		int i = adminDao.updateAdminSel(admin);
		if(i>0) return true;
		return false;
	}

	@Override
	public boolean updateAdminPwd(Admin admin) {
		// TODO Auto-generated method stub
		int i = adminDao.updateAdminPwd(admin);
		if(i>0) return true;
		return false;
	}

	@Override
	public List<Vector> selectAdminAll() {
		// TODO Auto-generated method stub
		/*ResultSet rs = adminDao.selectAdminAll();
		List<Vector> list = new ArrayList<Vector>();
		
		try {
			while(rs.next()) {
				Vector vc = new Vector();
				vc.add(rs.getString("admin_id"));
				vc.add(rs.getString("admin_name"));
				vc.add(rs.getString("admin_account"));
				vc.add(rs.getString("admin_phone"));
				vc.add(rs.getString("admin_email"));
				vc.add(rs.getString("admin"));
				list.add(vc);
				System.out.println(list);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return list;*/
		ResultSet rs = adminDao.selectAdminAll();
		List list = new ArrayList();
		
		ResultSet rs1;
		String role = null;
		try {
			while(rs.next()) {
				int id = rs.getInt("admin_id");
				String name = rs.getString("admin_name");
				String account = rs.getString("admin_account");
				String phone = rs.getString("admin_phone");
				String email = rs.getString("admin_email");
				String time = rs.getString("admin_gen_time");
				rs1 = adminDao.selectAdminRole(new Admin(account));
				List<String>  list1= new ArrayList();
				while (rs1.next()) {
					role = rs1.getString("role_name");
					list1.add(role);
				}
				Admin admin = new Admin(id,name,account,phone,email,time,list1);
				list.add(admin);
				
			}	
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return list;
	}

}
